<template>
  <div class="product-list-filter">
    <el-form inline>
      <el-form-item prop="key">
        <el-input
          placeholder="商品名称或商品编号"
          size="small"
          v-model="form.key"
        ></el-input>
      </el-form-item>
      <el-form-item prop="minPrice">
        <el-input-number
          placeholder="最低价"
          size="small"
          v-model="form.minPrice"
        ></el-input-number>
      </el-form-item>
      <el-form-item prop="maxPrice">
        <el-input-number
          placeholder="最高价"
          size="small"
          v-model="form.maxPrice"
        ></el-input-number>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          type="datetime"
          placeholder="开始日期"
          align="right"
          size="small"
          v-model="form.beginTime"
      /></el-form-item>
      <el-form-item>
        <el-date-picker
          type="datetime"
          placeholder="结束日期"
          align="right"
          size="small"
          v-model="form.endTime"
      /></el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          size="small"
          @click="$emit('update:filter', form)"
          ><i class="el-icon-search"></i> 搜索</el-button
        >
        <el-button
          type="danger"
          size="small"
          @click="$emit('update:filter', initial)"
          ><i class="el-icon-delete"></i> 清空</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "ProductListFilter",
  props: {
    filter: {
      type: Object,
      default() {
        return {
          key: "",
          maxPrice: "",
          minPrice: "",
          beginTime: "",
          endTime: "",
        };
      },
    },
  },
  data() {
    return {
      form: { ...this.filter },
      initial: {
        key: "",
        maxPrice: "",
        minPrice: "",
        beginTime: "",
        endTime: "",
      },
    };
  },
  watch: {
    filter: {
      deep: true,
      handler() {
        this.form = { ...this.filter };
      },
    },
  },
};
</script>

<style scoped></style>
